package com.xieyong.mywebsite.mapper;

import com.github.pagehelper.Page;
import com.xieyong.mywebsite.model.entity.Article;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ArticleMapper {

    @Insert("INSERT INTO article (title, content, cover_img, state, category_id, create_id, create_time,update_id, update_time) " +
            " values (#{title}, #{content}, #{coverImg}, #{state}, #{categoryId}, #{createId},#{createTime},#{updateId}, #{updateTime})")
    void insert(Article article);


    @Update("UPDATE article set is_deleted = 1, deleted_id = #{operatorId}, deleted_time = #{deletedTime} where id = #{deletedId}")
    void delete(Integer deletedId, Integer operatorId, LocalDateTime deletedTime);

    @Update("UPDATE article set title = #{title}, content = #{content}, cover_img = #{coverImg}, state = #{state}, category_id = #{categoryId}, " +
            "  update_id = #{updateId}, update_time = #{updateTime} where id = #{id}")
    void update(Article article);

    List<Article> selectByCondition(LocalDateTime startTime,LocalDateTime endTime, @Param("article")Article article);

    @Select("SELECT * from  article where is_deleted = 0 and id = #{id}")
    Article selectById(Integer id);

    @Select("SELECT * from  article where is_deleted = 0")
    List<Article> selectAll();

}
